package com.fitso.model.dao.hibernate.type.measure;

import java.math.BigDecimal;

import com.fitso.model.bean.measure.Measure;
import com.fitso.model.bean.measure.mass.Mass;

/**
 * Conversion utility to/from the database/java type of {@link Mass} types
 * 
 * @author timothystorm
 * 
 */
public abstract class MassHibernateType extends MeasureHibernateType {

	protected BigDecimal convertToBigDecimal(Measure value) {
		return value == null ? null : getInstance().convert((Mass) value).getValue();
	}

	protected Measure convertToMeasure(BigDecimal value) {
		if (value == null) {
			return null;
		}
		Mass mass = getInstance();
		mass.setValue(value);
		return mass;
	}

	protected Measure copy(Measure value) {
		return value == null ? null : getInstance().convert((Mass) value);
	}

	public Class<Mass> returnedClass() {
		return Mass.class;
	}

	abstract protected Mass getInstance();
}
